package logic

import (
	"context"
	"encoding/json"
	"test-demo/model"

	"test-demo/goods_srv/goods"
	"test-demo/goods_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsListLogic {
	return &GoodsListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodsListLogic) GoodsList(in *goods.GoodsListReq) (*goods.Response, error) {
	// todo: add your logic here and delete this line
	re := model.List(int(in.Page), in.Search)
	if re == nil {
		return &goods.Response{
			Pong: "0",
		}, nil
	}
	ref, _ := json.Marshal(re)
	return &goods.Response{
		Pong: string(ref),
	}, nil
}
